package com.project.security;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.InternalAuthenticationServiceException;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

@Service
public class DetailsServiceImpl implements UserDetailsService {

    @Autowired
    private UserInfoDetailsServiceImpl studentInfoDetailsService;


    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        UserDetails user;

        // 首先查询学生表
        user = studentInfoDetailsService.loadUserByUsername(username);
        if (user != null) {
            return user;
        }

        throw new InternalAuthenticationServiceException("用户名或密码错误...");
    }
}